<?php

//$reurl = strstr($_SERVER["REQUEST_URI"], ".") ? $_SERVER["REQUEST_URI"] : rtrim($_SERVER["REQUEST_URI"], "/") . "/index.htm";
//$redirect = '?redirect=' . urlencode($reurl . "&ispost=" . $cf_ispost);

$redirect = $_REQUEST['redirect'] ? urldecode($_REQUEST['redirect']) : '';
$redirect = strstr($redirect,"ispost=1") ? '' : $redirect; 								//如果是post提交则不跳转
$reurl = $_REQUEST['reurl'] ? $_REQUEST['reurl'] : '';

$userauth = new AdminAuth($db);
// var_dump($userauth);die;
//$_SESSION["abc"] = 'aaa';
//dump($_SESSION);

switch($cf_action){
	case "index":
		if($userauth->check_islogin()){
			global $cf_admin_dpt_row;
			if($cf_admin_dpt_row)
			header("location:".SITE_ADDR.$cf_admin_dpt_row['menu_link']);
			else
			header("location:".SITE_ADDR."admin/index.htm");
			exit;
		}else{
			$smarty->mypage($cf_controller,$cf_action,0) ;
		}
	break;
	case "login":
            //dump($session);

		// check_verify($_POST['verify']);									//测试不验证
		$login = $userauth->login($_POST['username'],$_POST['password'],0);
		
		//$check = $userauth->check_power('index-index');
		if($login){
				 if($reurl){
					 go_url($reurl);
				 }else{
					 go_url(SITE_ADDR.'admin/index.htm');
				 }
                 
		//my_jump('Login Successful','信息提示',SITE_ADDR.'admin/index.htm',1);
                }else{
					my_jump('输入的账号与密码不正确','信息提示',SITE_ADDR.'admin/login.htm');
                }
	break;
	case "logout":
		$userauth->logout();
		my_jump('成功退出','信息提示',SITE_ADDR.'admin/login.htm',1);
	break;
	default:
	break;
	
	
	
}

$smarty->assign(array(
	'title'=>'admin',
	'reurl'=>$redirect
));
$smarty->mydisplay();
?>